package com.xxg.renrenproduct.controller;

import com.xxg.renrencommon.domain.result.BaseResult;
import com.xxg.renrenproduct.domain.query.*;
import com.xxg.renrenproduct.domain.result.ListCarryProductResult;
import com.xxg.renrenproduct.domain.result.ShopInfoResult;
import com.xxg.renrenproduct.service.CarryProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 带货管理
 *
 * @author szj
 * @date 2021/11/29
 */
@Api(tags = "带货管理")
@RestController
@RequestMapping("/carryProduct")
@AllArgsConstructor
public class CarryProductController {
    private final CarryProductService carryProductService;

    @ApiOperation("带货商品")
    @RequestMapping(value = "carry", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "带货商品参数", required = true, dataType = "CarryProductQuery")})
    public BaseResult<Void> carry(@RequestBody @Validated CarryProductQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return carryProductService.carry(userId, query);
    }

    @ApiOperation("根据状态查询我收到的带货申请")
    @RequestMapping(value = "listShopReceiveByStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "根据状态查询我收到的带货申请参数", required = true, dataType = "ListShopByStatusQuery")})
    public BaseResult<List<ShopInfoResult>> listShopReceiveByStatus(@RequestBody @Validated ListShopByStatusQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return carryProductService.listShopReceiveByStatus(userId, query);
    }

    @ApiOperation("根据状态和店铺查询我收到的带货申请")
    @RequestMapping(value = "listReceiveByStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "根据状态和店铺查询我收到的带货申请参数", required = true, dataType = "ListShopByStatusQuery")})
    public BaseResult<ListCarryProductResult> listReceiveByStatus(@RequestBody @Validated ListShopByStatusQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return carryProductService.listReceiveByStatus(userId, query);
    }

    @ApiOperation("根据状态查询我的带货申请")
    @RequestMapping(value = "listShopSendByStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "根据状态查询我的带货申请参数", required = true, dataType = "ListShopByStatusQuery")})
    public BaseResult<List<ShopInfoResult>> listShopSendByStatus(@RequestBody @Validated ListShopByStatusQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return carryProductService.listShopSendByStatus(userId, query);
    }

    @ApiOperation("根据状态和店铺查询我的带货申请")
    @RequestMapping(value = "listSendByStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "根据状态和店铺查询我的带货申请参数", required = true, dataType = "ListShopByStatusQuery")})
    public BaseResult<ListCarryProductResult> listSendByStatus(@RequestBody @Validated ListShopByStatusQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return carryProductService.listSendByStatus(userId, query);
    }

    @ApiOperation("审核我收到的带货申请")
    @RequestMapping(value = "verify", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "审核我收到的带货申请参数", required = true, dataType = "VerifyQuery")})
    public BaseResult<Void> verify(@RequestBody @Validated VerifyQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return carryProductService.verify(userId, query);
    }

    @ApiOperation("取消带货")
    @RequestMapping(value = "deleteCarry", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "取消带货参数", required = true, dataType = "DeleteCarryQuery")})
    public BaseResult<Void> deleteCarry(@RequestBody @Validated DeleteCarryQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return carryProductService.deleteCarry(userId, query);
    }
}
